import { Controller, Get, Inject, Query } from "@nestjs/common";
import { AppService } from "./app.service";
import { ClientProxy } from "@nestjs/microservices";
import { Observable } from "rxjs";

@Controller("")
export class AppController {
  constructor(
    private readonly appService: AppService,
    @Inject("CALC_SERVICE") private calcClient: ClientProxy,
  ) {}

  @Get()
  getHello(): string {
    return this.appService.getHello();
  }

  @Get("/ser1")
  getServer1(@Query("num") str): Observable<number> {
    const numArr = str.split(",").map((i) => parseInt(i));
    return this.calcClient.send("sum", numArr);
  }
}
